﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using ExtAspNet;
using FJASPX.Framwork.UI;
using FJASPX.Framwork.Helper;
using FJASPX.Service;
using log4net;
using FJASPX.Framwork.Constant;

namespace PlugNT.Cms.Web.Member.Store
{
    public partial class Default : EditPageBase<FJASPX.Domain.Store>
    {
        #region Property属性

        public IStoreService iStoreService { get; set; }

        public IUserService iUserService { get; set; }

        public override string PowerCode
        {
            get { throw new NotImplementedException(); }
        }
        #endregion
        #region Methods方法
        protected override bool FirstCallRead()
        {
            base.FirstCallRead();
            this.IsUpdate = true;
            FJASPX.Domain.User user = iUserService.GetUserByName(this.CurrentUser.UserName);
            if (!user.IsNull())
            {
                this.Model = iStoreService.GetByUser(user);
                if (!Model.IsNull())
                {
                    if (this.Model.Skin != null)
                        this.ddl_Theme.SelectedValue = this.Model.Skin;
                    else
                        this.ddl_Theme.SelectedValue = "Default";
                    if (!this.Model.Banner.IsEmpty())
                    {
                        this.img_PicD.Src = this.Model.Banner.GetResolvedUrl();
                    } 
                }
                else
                {
                    ExtAspNet.Alert.Show(Strings.STORE_UNOPEN);
                }
            }
            return true;
        }
        #endregion
        #region Events事件
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            FJASPX.Domain.User user = iUserService.GetUserByName(this.CurrentUser.UserName);
            if (!user.IsNull())
            {
                this.Model = iStoreService.GetByUser(user);
                if (!this.Model.IsNull())
                {
                    this.Model.Skin = this.ddl_Theme.GetValue(); 
                    this.Model.Banner = this.SavePic(this.Model.Banner, this.txt_file.GetValue(), Cfg.USERPIC_PAGE_PATH);
                    try
                    {
                        iStoreService.Update(this.Model);
                        //这里加清缓存操作
                        this.Success();
                        return;
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLog(Message.ERR, ex);
                    }
                    this.Fail();
                }
            }
        }
        #endregion

    }
}